

class Point {//最接近点对问题
    double x;
    double y;

    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
    // 计算两个点之间的距离
    public double distance(Point p) {
        double dx = x - p.x;
        double dy = y - p.y;
        return Math.sqrt(dx * dx + dy * dy);
    }
}

public class ClosestPairBF {
    // 计算最接近点对的距离
    public static double closestPair(Point[] points) {
        int n = points.length;
        double minDistance = Double.POSITIVE_INFINITY;//初始值设为无限大
        // 遍历所有点对
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double distance = points[i].distance(points[j]);
                minDistance = Math.min(minDistance, distance);
            }
        }

        return minDistance;
    }

    public static void main(String[] args) {
        Point[] points = {new Point(0, 0),
                new Point(1, 1),
                new Point(1, 1.5),
                new Point(2, 3),
                new Point(12, 16)};
        double minDistance = closestPair(points);
        System.out.println("The closest pair distance is: " + minDistance);
    }
}
